package com.generate.table;


import com.generate.span.DefaultSpanCallBack;
import com.generate.span.TableCallBack;

import java.util.*;

/**
 * 调剂单，调拨单，退回单的table数据
 */
public class Table {
    private int order;
    private int cellpadding;
    private int cellspacing;
    private String style = "";
    private String align = "center";
    private int border;
    private String title;


    private List<Tr> trs = new LinkedList<>();

    private Map<String, Object> extend = new LinkedHashMap<>();

    private List<Cell> cells = new LinkedList<>();

    private List<Map<String, String>> tableData;

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }

    public int getBorder() {
        return border;
    }

    public void setBorder(int border) {
        this.border = border;
    }

    public void addExtend(String key, Object obj) {
        this.extend.put(key, obj);
    }

    public List<Map<String, String>> getTableData() {
        return tableData;
    }

    public void setTableData(List<Map<String, String>> tableData) {
        this.tableData = tableData;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public List<Cell> getCells() {
        return cells;
    }

    public void setCells(List<Cell> cells) {
        this.cells = cells;
    }

    public List<Tr> getTrs() {
        return trs;
    }

    public void setTrs(List<Tr> trs) {
        this.trs = trs;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public int getCellpadding() {
        return cellpadding;
    }

    public void setCellpadding(int cellpadding) {
        this.cellpadding = cellpadding;
    }

    public int getCellspacing() {
        return cellspacing;
    }

    public void setCellspacing(int cellspacing) {
        this.cellspacing = cellspacing;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public String getAlign() {
        return align;
    }

    public void setAlign(String align) {
        this.align = align;
    }

    public void addTr(Tr tr) {
        trs.add(tr);
    }

    public void build() {
        this.build(null);
    }

    public  void build(TableCallBack spanCallBack) {
        if (spanCallBack == null) {
            spanCallBack = new DefaultSpanCallBack();
        }
        clear();
        spanCallBack.init(this);
        spanCallBack.build(this);
    }

    public void clear() {
        trs.clear();
    }

    public static class Cell {
        private String prop;
        private String field;

        public String getProp() {
            return prop;
        }

        public void setProp(String prop) {
            this.prop = prop;
        }

        public String getField() {
            return field;
        }

        public void setField(String field) {
            this.field = field;
        }
    }
}
